layui.use(['form','table','element','laytpl','layer','upload','laydate'], function() {
  var table = layui.table;
  var form = layui.form;
  var laydate = layui.laydate;
  var upload = layui.upload;
  //时间选择器
  laydate.render({
    elem: '#birth_date'
    ,type: 'date'
  });
  upload.render({
		elem : '#uploader',
		url : '/ssm/file/uploadImage.do',
		done : function(res) {
			if (res.code == '01') {
				$("#uploader")
						.html(
								"<img src='" + res.body + "' style='width: 100px;height: 130px;'/><p>点击重新上传，或将文件拖拽到此处</p>");
				$("#banner_path").val(res.body);
			} else {
				layer.alert("上传失败");
			}
		}
	});

  	init();
    function init(){
        $.post('/ssm/studentInfo/findById.do',function(data){
        	var data = data.body;
        	if(data!=null){
                $("#editForm input[id=id]").val(data.id);
                $("#editForm input[id=name]").val(data.name);
                $("#editForm select[id=sex]").val(data.sex);
                $("#editForm input[id=birth_date]").val(data.birth_date);
                $("#editForm input[id=age]").val(data.age);
                $("#editForm input[id=cellphone]").val(data.cellphone);
                $("#editForm input[id=address]").val(data.address);
                $("#editForm input[id=xueyuan]").val(data.xueyuan);
                $("#editForm input[id=zhuanye]").val(data.zhuanye);
                $("#editForm input[id=banji]").val(data.banji);
                $("#editForm input[id=jiguan]").val(data.jiguan);
                $("#editForm input[id=mianmao]").val(data.mianmao);
                $("#editForm input[id=studentNo]").val(data.studentNo);
                $("#editForm input[id=identity]").val(data.identity);
                $("#editForm input[id=minzu]").val(data.minzu);
                $("#editForm input[id=banner_path]").val(data.photo);
                $("#uploader").html("<img src='" + data.photo + "' style='width: 100px;height: 130px;'/><p>点击重新上传，拖拽到文件</p>");
                $(".save").text("需要修改请联系管理员");
                $(".save").attr("disabled","disabled");
                $(".status").text(data.status==0?'未通过':'已通过');
                $(".status").css("display","");
        	}
            form.render('select');
        })
    }

    	//表单提交事件
    layui.form.on('submit(btnSubmit)', function(data){
    	
    		var postData = {
    				id : $("#id").val(),
    				name : $("#name").val(),
    				sex : $("#sex").val(),
    				birth_date : $("#birth_date").val(),
    				age : $("#age").val(),
    				cellphone : $("#cellphone").val(),
    				address : $("#address").val(),
    				xueyuan : $("#xueyuan").val(),
    				zhuanye : $("#zhuanye").val(),
    				banji : $("#banji").val(),
    				jiguan : $("#jiguan").val(),
    				mianmao : $("#mianmao").val(),
    				studentNo : $("#studentNo").val(),
    				identity : $("#identity").val(),
    				minzu : $("#minzu").val(),
    				photo : $("#banner_path").val(),
    		}
            var qUrl="/ssm/studentInfo/save.do";
            $.post(qUrl,postData,function(res){
             if(res.code=="01"){
                 layer.closeAll();
                 layer.msg("保存成功");
                 location.reload();
             }else{
                 layer.msg("保存失败");
             }
         });
            return false;
    });

    
});